﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace ArkanoidX.UI
{
    class HighScoreRegister : Window
    {
        Text title;
        Text label;
        Editor editor;

        public String PlayerName = "";

        public HighScoreRegister(MainGame game)
            : base(game)
        {
            Rectangle rect = game.GameRectangle;
            int width = rect.Width;
            int height = rect.Height;
            width = width / 2;
            height = height * 4 / 5;
            int left = rect.Left + (rect.Width - width) / 2;
            int top = rect.Top + (rect.Height - height) / 2;
            this.SetRectangle(new Rectangle(left, top, width, height));

            title = new Text(game);
            title.Value = "High Score";
            title.Color = Color.Gold;
            title.Scale = new Vector2(2,2);
            title.Align(this.boundingRect, AlignType.TopCenter, 0, 20);
            this.AddChild(title);


            editor = new Editor(game);
            editor.Align(this.boundingRect, AlignType.Center, new Vector2(width * 0.8f, width * 0.1f),
                0, 0);

            Rectangle labelContainer = this.boundingRect;
            labelContainer.Height = editor.GetRectangle().Top - this.boundingRect.Top;

            label = new Text(game);
            label.Value = "Your Name:";
            label.Align(labelContainer, AlignType.BottomCenter, 0, 20);
            this.AddChild(label);

            editor.SetActive();

            this.AddChild(editor);
        }

        public override void Update(GameTime gameTime)
        {
            KeyboardState kbs = Keyboard.GetState();

            if (kbs.IsKeyDown(Keys.Enter) && !((MainGame)Game).lkbsUI.LastEnterPressed)
            {
                PlayerName = editor.Value;
                this.Close();
            }

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }
    }
}
